<?php

class Default_RpcController extends Cff_Controller_Action
{
    public function init()
    {
        
    }
    public function preDispatch ()
    {
        $this->domain = 'http://' . $_SERVER['SERVER_NAME'];
    }

    public function xmlRpcAction ()
    {
        $server = new Zend_XmlRpc_Server();
        Zend_XmlRpc_Server_Fault::attachFaultException('Zend_Exception');
        $cacheFile = APPLICATION_PATH . '/../data/xmlRpc/xmlrpc.cache';
        if (! Zend_XmlRpc_Server_Cache::get($cacheFile, $server))
        {
            $server->setClass("Default_Service_XmlRpc", "xml_rpc");
            Zend_XmlRpc_Server_Cache::save($cacheFile, $server);
        }
        
        echo $server->handle();
    }

    public function indexAction ()
    {
        try
        {
            
            $client = new Zend_XmlRpc_Client(
                    $this->domain . "/default/rpc/xml-rpc/");
            // 方法1
            echo $client->call('xml_rpc.sendMail', 
                    array(
                            1,
                            array(
                                    "123",
                                    "345"
                            ),
                            array(
                                    "123",
                                    "345"
                            ),
                            array(
                                    "123",
                                    "345"
                            ),
                            "12314",
                            "12314",
                            array(
                                    "123",
                                    "345"
                            ),
                            array(
                                    "123",
                                    "345"
                            )
                    ));
//             exit();
            
            // 方法2
            $xml_rpc = $client->getProxy('xml_rpc');
            echo $xml_rpc->sendMail(1, 
                    array(
                            "123",
                            "345"
                    ), 
                    array(
                            "123",
                            "345"
                    ), 
                    array(
                            "123",
                            "345"
                    ), "12314", "12314", 
                    array(
                            "123",
                            "345"
                    ), 
                    array(
                            "123",
                            "345"
                    ));
            
        } catch (Zend_XmlRpc_Client_HttpException $e)
        {
            
            echo $e->getCode();
            echo $e->getMessage();
        }
    }
}